/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.ufrpe.bsi.dao;

import java.beans.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 *
 * @author bruna
 */
public class Conexao {
    private String driver = "com.mysql.jdbc.Driver";
    private String url = "jdbc:mysql://localhost:3306/db_organizer_project" ;
    private String login = "root"; 
    private String senha = "";   
    private Connection con = null; 
    
    public Connection getCon() throws ClassNotFoundException, SQLException{
        if(con == null){
            Class.forName(driver);
            con = DriverManager.getConnection(url,login, senha);   
        }
        return con;
    }
    
    public Statement getStatement() throws ClassNotFoundException, SQLException{//para não ficar repetindo toda vez q precisar de um statement
        return (Statement) getCon().createStatement();   //problema no usuariodao, ele não consegue enxergar  executeQuery    
    }
    
    public PreparedStatement getPreparedStatement(String sql) throws ClassNotFoundException, SQLException{//mesmo motivo
        return getCon().prepareStatement(sql);
    }
    
    public void fecharCon() throws SQLException{
        con.close();
    }
}
